/**
 * Copyright(c) 2025 hbswxx.com, All Rights Reserved. Author: kouqiang Create date: 2025/6/4
 */
package cn.sw.syncdata.job.heart;

import cn.sw.syncdata.entity.EquipmentsMonitoringLog;
import cn.sw.syncdata.util.Util;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashSet;
import java.util.Random;

/**
 * description: 设备监控日志生成
 *
 * @author kouqiang
 * @date 2025/6/4 16:26
 */
@Slf4j
@RequiredArgsConstructor
public class ThreadCreateEMLog implements Runnable {
    private final int total;
    private final String sdate;
    private final String edate;
    private final String fileName;
    private final String[] indexList = {"02f5f734b96f4f3cbd08324fda0c38a2",
            "03bedd8a4c314159ba35f15692f5d2e8",
            "04e7e8b8d0e04926bb8c14a99ee7fe79",
            "0aa7dafca4e24df0b49646afac872f73",
            "12c866be0d9b46c2b6b48c0a520a2309",
            "138669aaa8ba4ed699700282bdbea26c",
            "145735aa1cbf49e3891a9b313ef817c5",
            "14bedca3506d4aeb972d6926571012e3",
            "154eb18afc574ae3a98cd79ff51a23c2",
            "17e516ffe3d94db98830ace0db07723c",
            "1976abec51cb45c8a6ae7f2cc2fbd4da",
            "1a94dc5f22bf46b99c0d04559db92eb1",
            "1c8064cff3ef48a484d129c22c7e98a5",
            "21e7fec9ef4448db9710bb29149f5542",
            "2851225843b8480e96aaa0d015f51c14",
            "2ea2ca19e70c466c92ce6c244644a415",
            "2f8d9900d9074fdfb07e5a1aa1d5b5af",
            "34917b16fa9945f491560ecffa088cc3",
            "34e314228eb941c6931029030fdae8c0",
            "355c5116058045cea25440a1c34da320",
            "3dec9ccca3954c2f9460d93d30e354a7",
            "41c137d755124b689621506e9f14dd5e",
            "41c3d08e0e644c0dbff33ca797a4f9f9",
            "420d90041a404bcea73b7441d67ada24",
            "45dbe3d9e8d6437281c03347c9a6b3f1",
            "506169fff4d64eadb012a93d3cf78cad",
            "5214ee19b6834bc3bb79d50a14bb544d",
            "54a168746dcd4dbeb33f55200ac1b6f5",
            "5e4bac2f87c244b1adaf35cf0d890939",
            "62445bfdc7d94106998ee5fac2026d33",
            "624a011492c34c20bc414149a26f810e",
            "6288a7c5e96b45cdad19e78ab530fe1b",
            "629bb6536c254e7f80fae3efaeb02663",
            "6a496f37a5314fbf9d8d5b2c396c55cb",
            "71bfdfe0e7f8492597877a9d82ef7f89",
            "7677bf4879954a848074ba0744270451",
            "79c84980a42c42b9aaaffe62b36e7907",
            "7a03666537054739b26832f73992f3b4",
            "7bf70db212e344659c3828e4bc4ea206",
            "7f5ee16a07094fb39f4d16360001c90d",
            "80b61c4aafac482c95d92c0700d3b48f",
            "82794a13b8f94b7ba253e5f972a1a302",
            "8dc65a9af3a54278a9a18ba469a8421a",
            "8dc908ead48f4c2ea4f5f673bfcc61cc",
            "92d81b58e126479bb3db023d2aceaddc",
            "9caeb417487b459e90cd65791492c87c",
            "9f5ad832dc97466bb2b3bdc9a829a82a",
            "a1bef9d170054f22822ea0d4d3797eb5",
            "aeb766800e2d4efc9142fd9fc8dd3da7",
            "afcdcd4659584da89b70a6b1e30d7b92",
            "ajdl1000044",
            "ajdl1000045",
            "ajdl1000046",
            "ajdl1000047",
            "ajdl1000048",
            "ajdl1000049",
            "ajdl1000050",
            "ajdl1000051",
            "ajdl1000052",
            "ajdl1000053",
            "ajdl1000054",
            "ajdl1000055",
            "ajdl1000056",
            "ajdl1000057",
            "ajdl1000058",
            "ajdl1000059",
            "ajdl1000060",
            "ajdl1000061",
            "ajdl1000062",
            "ajdl1000063",
            "b02af56c49da45f9bf2650734f5bb7ac",
            "b03e6709d8db42768060311f6fc70de0",
            "b0ef692bd22a43d7aa61245a263993de",
            "b23f8d339f6249289f76389ccbe0c573",
            "b274e0d76ec3438bac9710c01a19cc23",
            "b519e434a7c2439783a291fcc6f70ab8",
            "b71d8b7848684b97bfed870ce0a93065",
            "b8939a8c684540a5acd2813a9450ddd8",
            "bb51f770ee534844bc8aa2b15e107efe",
            "bc35f28bb15b41aea803622836721c88",
            "be020a13e4634fa7bde29ca08e0efb8e",
            "c0634dca267643d0b78e5b56399c9c6c",
            "c21db05d37624301941c9cbdadc4e6ca",
            "c6210f68b46f49dbaf0eb532b3c81a45",
            "c67e7b1e9afc499e9a1601e5e0f59b05",
            "c9453ccc4ce74eacb7206efc54acc5a6",
            "ca423e1c4104417eba71878fe42091e5",
            "ca454daca7d84eab94dee0a24811920a",
            "d06bea6a406d4cb8ae815834ed19d924",
            "d0bd629df32e4f089791627203b675b4",
            "d25787473ab4410da2840ef031221e3c",
            "d2f5191a1d474db7a95dfb01516c09d0",
            "d3cf386f9540480da27f77c9a2851359",
            "d4b664e180de4c3ead6c2f44291be318",
            "d4dc50861d65411a9aa6f83c5d1fedc6",
            "d5bf25752a3c46d7ac7205e631a6b45a",
            "d672731a5cca48ae9d4a4ad19c4af074",
            "d799fde277aa4dd8aabc3b6d94c4c36d",
            "d9d90e42f8a24a6d9a2100a534e13378",
            "de478f07a0384acdbb458a4876ac6da2",
            "drxj1000115",
            "drxj1000116",
            "drxj1000117",
            "drxj1000118",
            "drxj1000119",
            "drxj1000120",
            "drxj1000121",
            "drxj1000122",
            "drxj1000123",
            "drxj1000124",
            "drxj1000125",
            "drxj1000126",
            "drxj1000127",
            "drxj1000128",
            "drxj1000129",
            "drxj1000130",
            "drxj1000131",
            "drxj1000132",
            "drxj1000133",
            "drxj1000134",
            "drxj1000135",
            "drxj1000136",
            "drxj1000137",
            "drxj1000138",
            "drxj1000139",
            "drxj1000140",
            "e16724635ac94091819e8c2313bb6cf1",
            "e1750a2787fa4fab9c3c04744af64e0f",
            "e4413a37a5b1488faf46a1441b22e5d4",
            "e6b2e2e4f3c4480baf18ec38fd51a812",
            "e8fabf70d6854c1c9d3a725bbea45103",
            "ec3c65528f054be188400129adcc529b",
            "ec412e501ca34ef0b184360b26541018",
            "ed4e2d3c7879446e8ff328ba674a0ab1",
            "ee49d5b7f3f84240aed92192a7e556d4",
            "eed8f655d3274c6b823236a1383b4140",
            "f8383a03d2414bb19518fddb66ed03c5",
            "f8dbefec76fb43d3a13395233c97a62f",
            "fabe3939e0964e0db1fecf474732d10b",
            "fe7523fbd25a4c0a9eedbbfa6b7b7a55",
            "wxjy1000000",
            "wxjy1000001",
            "wxjy1000002",
            "wxjy1000003",
            "wxjy1000004",
            "wxjy1000005",
            "wxjy1000006",
            "wxjy1000022",
            "wxjy1000024",
            "wxjy1000025",
            "wxjy1000026",
            "wxjy1000027",
            "wxjy1000028",
            "wxjy1000029",
            "wxjy1000030",
            "wxjy1000031",
            "wxjy1000032",
            "wxjy1000033",
            "wxjy1000034",
            "wxjy1000035",
            "wxjy1000036",
            "xajy1000003",
            "xajy1000010",
            "xajy1000011",
            "xajy1000012",
            "xajy1000018",
            "xajy1000019",
            "xajy1000020",
            "xajy1000021",
            "xajy1000022",
            "xajy1000023",
            "xfnq1000020",
            "xfnq1000021",
            "xfnq1000022",
            "xfnq1000023",
            "xfnq1000024",
            "xfnq1000025",
            "xfnq1000026",
            "xfnq1000027",
            "xfnq1000028",
            "xfnq1000029",
            "xfnq1000030",
            "xfnq1000031",
            "xfnq1000032",
            "xfnq1000033",
            "xfnq1000034",
            "xfnq1000035",
            "xfnq1000043",
            "xfnq1000044",
            "xfnq1000045",
            "xfnq1000046",
            "xfnq1000047",
            "xfnq1000048",
            "xfnq1000049",
            "xfnq1000050",
            "xyjy1000015",
            "xyjy1000016",
            "xyjy1000017",
            "xyjy1000018",
            "xyjy1000019",
            "xyjy1000020",
            "xyjy1000021",
            "xyjy1000022",
            "xyjy1000023",
            "xyjy1000024",
            "xyjy1000025",
            "xyjy1000026",
            "xyjy1000027",
            "xyjy1000028",
            "xyjy1000029",
            "xyjy1000030",
            "xyjy1000031",
            "xyjy1000038",
            "xyjy1000039",
            "xyjy1000040",
            "xyjy1000041",
            "xyjy1000042",
            "xyjy1000043",
            "xyjy1000044",
            "xyjy1000045",
            "xyjy1000046",
            "xyjy1000047",
            "xyjy1000048",
            "xyjy1000049",
            "xyjy1000050",
            "xyjy1000051",
            "xyjy1000052",
    };
    private final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;

    @Override
    public void run() {
        Random random = new Random();
        LocalDateTime sDateTime = LocalDateTime.parse(sdate + "T00:00:00", formatter);
        LocalDateTime eDateTime = LocalDateTime.parse(edate + "T23:59:59", formatter);
        StringBuffer sb = new StringBuffer();
        int indexCount = indexList.length;
        HashSet<String> hashSet = new HashSet<>();
        sb.append("equipments_indexcode, datetime_logtime, onlinestatus");
        sb.append("\n");

        for (int i = 0; i < total; i++) {
            LocalDateTime newDateTime = Util.randomBetween(sDateTime, eDateTime);
            EquipmentsMonitoringLog newInfo = new EquipmentsMonitoringLog();
            newInfo.setEquipmentsIndexcode(indexList[random.nextInt(indexCount)]);
            newInfo.setDatetimeLogtime(newDateTime);
            newInfo.setOnlinestatus(random.nextInt(4));
            String line = newInfo.toString();
            if(!hashSet.contains(line))
            {
                hashSet.add(line);
                sb.append(line);
                sb.append("\n");
            }
            if (i % 2000 == 0) {
                wrteList(sb.toString());
                sb.setLength(0);
            }
        }
        if(sb.length()>0)
            wrteList(sb.toString());
    }
    private void wrteList(String lines) {
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true))) {
            writer.write(lines);
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
